"""
BaoStock日K数据VO模型

本文件定义BaoStock日K数据的视图对象模型。
"""
from decimal import Decimal
from datetime import datetime, date
from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel
from pydantic_validation_decorator import NotBlank
from typing import Optional
from module_admin.annotation.pydantic_annotation import as_query


class BaoStockDailyModel(BaseModel):
    """
    BaoStock股票日K线表对应pydantic模型
    """
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    id: Optional[int] = Field(default=None, description='id')
    trade_date: Optional[date] = Field(default=None, description='交易日期')
    symbol: Optional[str] = Field(default=None, description='股票代码（原始格式，如600000）')
    bs_code: Optional[str] = Field(default=None, description='BaoStock代码（如sh.600000）')
    open: Optional[Decimal] = Field(default=None, description='开盘价')
    close: Optional[Decimal] = Field(default=None, description='收盘价')
    high: Optional[Decimal] = Field(default=None, description='最高价')
    low: Optional[Decimal] = Field(default=None, description='最低价')
    preclose: Optional[Decimal] = Field(default=None, description='前收盘价')
    volume: Optional[Decimal] = Field(default=None, description='成交量')
    amount: Optional[Decimal] = Field(default=None, description='成交额')
    adjustflag: Optional[str] = Field(default=None, description='复权状态（1=后复权，2=前复权，3=不复权）')
    turn: Optional[Decimal] = Field(default=None, description='换手率')
    tradestatus: Optional[str] = Field(default=None, description='交易状态（1=正常，0=停牌）')
    pct_chg: Optional[Decimal] = Field(default=None, description='涨跌幅')
    is_st: Optional[str] = Field(default=None, description='是否ST股（1=是，0=否）')
    create_time: Optional[datetime] = Field(default=None, description='创建时间')
    update_time: Optional[datetime] = Field(default=None, description='更新时间')

    @NotBlank(field_name='trade_date', message='交易日期不能为空')
    def get_trade_date(self):
        return self.trade_date

    @NotBlank(field_name='symbol', message='股票代码不能为空')
    def get_symbol(self):
        return self.symbol

    def validate_fields(self):
        self.get_trade_date()
        self.get_symbol()


class BaoStockDailyQueryModel(BaoStockDailyModel):
    """
    BaoStock股票日K线不分页查询模型
    """
    pass


@as_query
class BaoStockDailyPageQueryModel(BaoStockDailyQueryModel):
    """
    BaoStock股票日K线分页查询模型
    """
    page_num: int = Field(default=1, description='当前页码')
    page_size: int = Field(default=10, description='每页记录数')


class DeleteBaoStockDailyModel(BaseModel):
    """
    删除BaoStock股票日K线模型
    """
    model_config = ConfigDict(alias_generator=to_camel)

    ids: str = Field(description='需要删除的id')

